package com.ld.wms.business.notice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ld.wms.business.notice.mapper.WarnConfigMapper;
import com.ld.wms.business.notice.model.WarnConfigModel;
import com.ld.wms.business.notice.service.WarnConfigService;
import com.ld.wms.business.notice.vo.req.WarnConfigReqVo;
import com.ld.wms.business.notice.vo.resp.WarnConfigRespVo;
import com.ld.wms.common.vo.GenerateListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangfeng
 * @since 2025-04-23
 */
@Service
public class WarnConfigServiceImpl extends ServiceImpl<WarnConfigMapper, WarnConfigModel> implements WarnConfigService {

    @Autowired
    private WarnConfigMapper warnConfigMapper;

    @Override
    public void configWarn(WarnConfigReqVo reqVo) {
        WarnConfigModel warnConfig = new WarnConfigModel();
        BeanUtils.copyProperties(reqVo, warnConfig);
        QueryWrapper<WarnConfigModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(WarnConfigModel.ID, 1);
        WarnConfigModel warnConfigModel = warnConfigMapper.selectOne(queryWrapper);
        if (ObjectUtils.isEmpty(warnConfigModel)) {
            warnConfigMapper.insert(warnConfig);
        } else {
            warnConfig.setId(warnConfigModel.getId());
            warnConfigMapper.updateById(warnConfig);
        }
    }

    @Override
    public WarnConfigRespVo getWarnConfig() {
        WarnConfigRespVo warnConfigRespVo = new WarnConfigRespVo();
        WarnConfigModel warnConfigModel = warnConfigMapper.selectById(1L);
        BeanUtils.copyProperties(warnConfigModel, warnConfigRespVo);
        return warnConfigRespVo;
    }

}
